# import uuid
# from Crypto.Cipher import DES
# from Crypto.Util.Padding import pad, unpad


# def get_key(len=8):
#     """获取指定位数的动态密钥
#     """
#     key = str(uuid.uuid4()).replace('-', '')[4:4+len].upper()
#     return key.encode('utf-8')


# class My_DES_ECB():
#     def __init__(self, key):
#         # 密钥必须为8位
#         self.key = key
#         self.mode = DES.MODE_ECB
#         self.cryptor = DES.new(self.key, self.mode)

#     def encrypt(self, plain_text):
#         encrypted_text = self.cryptor.encrypt(pad(plain_text.encode('utf-8'), DES.block_size))
#         return encrypted_text

#     def decrypt(self, encrypted_text):
#         plain_text = self.cryptor.decrypt(encrypted_text)
#         plain_text = unpad(plain_text, DES.block_size).decode()
#         return plain_text


# if __name__ == '__main__':
#     # key = get_key()
#     # print(f'key---{key}')
#     # key = b'A126DD97'
#     key = b'64FE1C33'
#     pc = My_DES_ECB(key)  # 初始化密钥,
#     # e = b'ZDX3\xd5\xab\x1a:\x86\nTo\xab:\xff@'
#     # e = pc.encrypt("我是谁")
#     # print(e)
#     # 获取文档数据
#     # with open('new2.txt', 'r+', encoding='utf-8') as fd:
#     # aa_list = ''
#     with open('HK32ASPIN060K8U7.pm', 'rb') as fd:
#         # print(f'fd---{fd.read()}')
#         d = pc.decrypt(fd.read())
#         print(d)


from cryptography.fernet import Fernet

class My_DES_ECB():
    """工程文件解析"""
    def __init__(self) -> None:
        # 生成密钥
        self.key = Fernet.generate_key()
        # self.key = b'78FA2306'
        # 创建加密器
        self.cipher = Fernet(self.key)
        # 要加密的数据
        self.plain_text = b"Hello, World!"
        self.encrypted_text = b"Hello, World!"
        self.encrypt()
        self.decrypt()
    
    def encrypt(self):
        # 加密数据
        self.encrypted_data = self.cipher.encrypt(self.plain_text)
        print("加密后的数据:", self.encrypted_data)

    def decrypt(self):
        # 解密数据
        decrypted_data = self.cipher.decrypt(self.encrypted_data)
        print("解密后的数据:", decrypted_data)

My_DES_ECB()
